package com.zihan.service.impl;

import com.zihan.constant.ParamsConstant;
import com.zihan.domain.entity.ProjectMilestone;
import com.zihan.domain.result.Result;
import com.zihan.mapper.ProjectMapper;
import com.zihan.mapper.ProjectMilestoneMapper;
import com.zihan.service.IProjectMilestoneService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 项目节点表 服务实现类
 * </p>
 *
 * @author zhangzihan
 * @since 2025-10-20
 */
@Service
public class ProjectMilestoneServiceImpl extends ServiceImpl<ProjectMilestoneMapper, ProjectMilestone> implements IProjectMilestoneService {

    @Resource
    private IProjectMilestoneService projectMilestoneService;
    @Resource
    private ProjectMapper projectMapper;

    // 保存数据节点
    @Override
    public Result<String> saveData(ProjectMilestone projectMilestone) {
        // 保存节点
        projectMilestoneService.save(projectMilestone);
        return Result.success("添加节点成功");
    }
    // 获取节点列表
    @Override
    public Result<List<ProjectMilestone>> getList(Long projectId) {
        if (Objects.isNull(projectId)) {
            return Result.error(ParamsConstant.LACK_PARAMS);
        }
        List<ProjectMilestone> milestone = this.lambdaQuery().eq(ProjectMilestone::getProjectId, projectId)
                .orderByAsc(ProjectMilestone::getStartDate).orderByAsc(ProjectMilestone::getEndDate).list();
        return Result.success(milestone);

    }


    /**
     * 修改数据节点
     * @param projectMilestone
     * @return
     */
    @Override
    public Result<String> updateData(ProjectMilestone projectMilestone) {
        projectMilestoneService.updateById(projectMilestone);
        return Result.success("修改节点成功");
    }
}
